<template>
  <div class="checkbox-container" :class="{ center }" @click="setCheckBoxChecked()">
    <div class="checkbox" :class="{ checked }">
      <span class="iconfont icon-xuanzhong"></span>
    </div>
    <slot></slot>
  </div>
</template>

<script>
export default {
  props: {
    checked: {
      type: Boolean,
      default: false
    },
    center: {
      type: Boolean,
      default: false
    }
  },

  methods: {
    /**
     * 设置当前checkbox是选中的状态
     */
    setCheckBoxChecked () {
      this.$emit('onChange', !this.checked)
    }
  }
}
</script>

<style lang="less" scoped>
@import "../../styles/variable.less";

.checkbox-container {
  cursor: pointer;
  display: flex;
  width: fit-content;
  .checkbox {
    align-items: center;
    border: 1px solid @border-grey;
    display: flex;
    width: 18px;
    height: 18px;
    margin-right: 10px;
    justify-content: center;
    .iconfont {
      color: #d4282d;
      display: none;
      font-size: 14px;
    }
    &.checked {
      .iconfont {
        display: block;
      }
    }
  }
  .center {
    align-items: center;
  }
}
</style>
